<?php

namespace app\common\model\question;

use app\admin\model\Admin;
use app\common\model\Model;
use app\common\model\User;
use traits\model\SoftDelete;

class MoneyApply extends Model
{

    use SoftDelete;

    // 表名
    protected $name = 'user_money_apply';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_name',
    ];

    const STATUS = [
        self::STATUS_ING => '审核中',
        self::STATUS_SUCCESS => '提现成功',
        self::STATUS_REJECT => '已拒绝',
    ];

    const STATUS_ING = 0;
    const STATUS_SUCCESS = 1;
    const STATUS_REJECT = 2;

    public function getStatusNameAttr($value, $data)
    {
        return $value ? $value : self::STATUS[$data['status']] ?? '';
    }

    public function user()
    {
        return $this->belongsTo(User::class)->setEagerlyType(0);
    }

    public function admin()
    {
        return $this->belongsTo(Admin::class, 'admin_id', 'id')->setEagerlyType(1);
    }
}
